package me.samlss.lighter.shape;

import ohos.agp.render.*;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;

/**
 * 高亮形状基类
 *
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public abstract class LighterShape {
    /**
     * 高亮矩形位置
     */
    protected RectFloat highlightedViewRect;
    /**
     * Lighter 矩形路径
     */
    protected Path path;
    /**
     * Lighter 画笔
     */
    protected Paint paint;

    protected LighterShape(float blurRadius) {
        path = new Path();
        paint = new Paint();

        paint.setDither(true);
        paint.setAntiAlias(true);
        paint.setColor(Color.WHITE);
//        paint.setColorFilter(new ColorFilter(Color.WHITE.getValue(), BlendMode.SRC_OVER));

        if (blurRadius > 0) {
            paint.setMaskFilter(new MaskFilter(blurRadius, MaskFilter.Blur.SOLID));
        }
    }

    /**
     * Draw the highlighted view.
     * @param canvas
     */
    public void onDraw(Canvas canvas) {
        if (path != null
                && paint != null) {
            canvas.drawPath(path, paint);
        }
    }

    /**
     * Set {@link RectFloat} the highlighted view.
     * @param rect
     */
    public void setViewRect(RectFloat rect) {
        highlightedViewRect = rect;
    }

    /**
     * Get {@link RectFloat} the highlighted view.
     *
     * @return RectFloat
     */
    public RectFloat getViewRect() {
        return highlightedViewRect;
    }

    /**
     * Returns true if the view rect is empty (left >= right or top >= bottom)
     *
     * @return ViewRectEmpty
     */
    public boolean isViewRectEmpty() {
        return highlightedViewRect == null
                || highlightedViewRect.isEmpty();
    }

    /**
     * Set a custom paint when draw this shape.
     *
     * @param paint
     */
    public void setPaint(Paint paint) {
        this.paint = paint;
    }

    /**
     * Get shape path.
     *
     * @return Path
     */
    public Path getShapePath() {
        return path;
    }
}
